.global set_idt
.extern idtd

set_idt:
	lidt idtd
	ret

#ISR Handlers
.global isr0
.global isr1
.global isr2
.global isr3
.global isr4
.global isr5
.global isr6
.global isr7
.global isr8
.global isr9
.global isr10
.global isr11
.global isr12
.global isr13
.global isr14
.global isr15
.global isr16
.global isr17
.global isr18
.global isr19
.global isr20
.global isr21
.global isr22
.global isr23
.global isr24
.global isr25
.global isr26
.global isr27
.global isr28
.global isr29
.global isr30
.global isr31
.extern isr_handler

#In these functions first we push a fake error code, if the interrupt doesn't put on already
# then we push the id of the interrupt to know how to handle it
isr0:
	cli
	push $0x0
	push $0x0
	jmp isr_stub_handler

isr1:
	cli
	push $0x0
	push $0x1
	jmp isr_stub_handler

isr2:
	cli
	push $0x0
	push $0x2
	jmp isr_stub_handler

isr3:
	cli
	push $0x0
	push $0x3
	jmp isr_stub_handler


isr4:
	cli
	push $0x0
	push $0x4
	jmp isr_stub_handler

isr5:
	cli
	push $0x0
	push $0x5
	jmp isr_stub_handler

isr6:
	cli
	push $0x0
	push $0x6
	jmp isr_stub_handler

isr7:
	cli
	push $0x0
	push $0x7
	jmp isr_stub_handler

isr8:
	cli
	push $0x8
	jmp isr_stub_handler

isr9:
	cli
	push $0x0
	push $0x9
	jmp isr_stub_handler

isr10:
	cli
	push $0xA
	jmp isr_stub_handler

isr11:
	cli
	push $0xB
	jmp isr_stub_handler

isr12:
	cli
	push $0xC
	jmp isr_stub_handler

isr13:
	cli
	push $0xD
	jmp isr_stub_handler

isr14:
	cli
	push $0xE
	jmp isr_stub_handler

isr15:
	cli
	push $0x0
	push $0xF
	jmp isr_stub_handler

isr16:
	cli
	push $0x0
	push $0x10
	jmp isr_stub_handler

isr17:
	cli
	push $0x0
	push $0x11
	jmp isr_stub_handler

isr18:
	cli
	push $0x0
	push $0x12
	jmp isr_stub_handler

isr19:
	cli
	push $0x0
	push $0x13
	jmp isr_stub_handler

isr20:
	cli
	push $0x0
	push $0x14
	jmp isr_stub_handler

isr21:
	cli
	push $0x0
	push $0x15
	jmp isr_stub_handler

isr22:
	cli
	push $0x0
	push $0x16
	jmp isr_stub_handler

isr23:
	cli
	push $0x0
	push $0x17
	jmp isr_stub_handler

isr24:
	cli
	push $0x0
	push $0x18
	jmp isr_stub_handler

isr25:
	cli
	push $0x0
	push $0x19
	jmp isr_stub_handler

isr26:
	cli
	push $0x0
	push $0x1A
	jmp isr_stub_handler

isr27:
	cli
	push $0x0
	push $0x1B
	jmp isr_stub_handler

isr28:
	cli
	push $0x0
	push $0x1C
	jmp isr_stub_handler

isr29:
	cli
	push $0x0
	push $0x1D
	jmp isr_stub_handler

isr30:
	cli
	push $0x0
	push $0x1E
	jmp isr_stub_handler

isr31:
	cli
	push $0x0
	push $0x1F
	jmp isr_stub_handler

isr_stub_handler:
	pusha
	push %ds
	push %es
	push %fs
	push %gs
	mov $0x10, %ax  # Load the Kernel Data Segment descriptor!
	mov %ax  , %ds
	mov %ax  , %es
	mov %ax  , %fs
	mov %ax  , %gs
	mov %esp, %eax
	push %eax
	mov $(isr_handler), %eax 
	call *%eax       # A special call, preserves the 'eip' register
	pop %eax
	pop %gs
	pop %fs
	pop %es
	pop %ds
	popa
	add $0x8, %esp
	iret

